/* 
Scenic Graphics Library
Copyright (C) 2007 Jouni Tulkki

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USApackage scenic;
*/

#define DEBUG

#ifdef DEBUG

#include <stdio.h>

#ifdef WIN32
#define _RDTSC_STACK(ts) \
	__asm rdtsc \
	__asm mov DWORD PTR [ts], eax \
	__asm mov DWORD PTR [ts+4], edx

__inline unsigned __int64 readTimeStampCounter() {
	unsigned __int64 t;
	_RDTSC_STACK(t);
	return t;
}
#else
typedef long long __int64;

inline volatile long long readTimeStampCounter() {
   register long long TSC asm("eax");
   asm volatile (".byte 15, 49" : : : "eax", "edx");
   return TSC;
} 
#endif

class FunctionObject
{
public:
	char *name;
	__int64 executionTime;
	__int64 callCount;

	FunctionObject(char *name);

	char *getName()
	{
		return name;
	}

	static void printProfilingInformation();
};

class FunctionExecutionObject
{
	FunctionObject *function;
	__int64 startTime;
public:
	FunctionExecutionObject(FunctionObject *function);
	~FunctionExecutionObject();
};

#define ENTER(a) static FunctionObject _functionObject(#a); FunctionExecutionObject _functionExecutionObject(&_functionObject);

#else

#define ENTER(a)

#endif

